#include "cvmatdetectthread.h"

CvmatDetectThread::CvmatDetectThread(QObject *parent ) : DetectThread(parent) {}

void CvmatDetectThread::init(std::shared_ptr<Inference> inference1,
                                    bool run_with_cuda,bool islabel, ThreadSafeQueue *matQueue2)
{



    this->inference=inference1;
    this->islabel=islabel;
    this->RunWithCuda=run_with_cuda;
    this->matQueue=matQueue2;
}

void CvmatDetectThread::do_detect()
{
    if(this->matQueue==nullptr){
        return;
    }
this->matQueue->clear();
    int idx = 0;

    auto radio_button = islabel;
    qDebug()<<"CvmatDetectThread STOP "<<STOP;
    while (!STOP)
    {
        idx++;

        cv::Mat frame = this->matQueue->pop();
        if (frame.empty())
            return;
        //cv::flip(frame, frame, cv::RotateFlags::ROTATE_180);
        this->inference->doPredict(frame, radio_button);
        QPixmap map = commons::cvMatToQPixmap(frame);
        //this->main_window->show_img(map);
        // 等 33
        emit imageReady(map);
        cv::waitKey(33);
    }
    qDebug()<<"CvmatDetectThread end STOP "<<STOP;

}

int CvmatDetectThread::get_detect_id()
{
    return DetectThread::CameraDetectThreadID;
}
